import { login } from '@/api/user';

const getDefaultData= () =>{
  return {
    name:'',
    token:'',
  }
}
const state =getDefaultData;
const mutations={
  SET_NAME:(state,name)=>{
    state.name=name;
  },
  SET_TOKEN:(state,token)=>{
    state.token=token;
  },
};
const actions={
  login({ commit },userInfo){
    const { username, password}=userInfo;
    return new Promise((resolve,reject)=>{
      login({ username: username.trim(), password: password,mobileLogin:userInfo.mobileLogin }).then(response => {
        const data={
          token:1
        };
        commit('SET_TOKEN', data.token)
        localStorage.setItem('token',data.token)
        // setToken(data.token)
        resolve()
      }).catch(error => {
        reject(error)
      })
    })
  }
};
export default{
  namespaced: true,
  state,
  mutations,
  actions
}
